package me.ilich.piet.interpreter;

import java.util.Set;

import me.ilich.piet.interpreter.elements.Coordinate;
import junit.framework.TestCase;

public class CoordinateTestCase extends TestCase {
	
	public void testEquals(){
		Coordinate c1 = Coordinate.instance(0, 0);
		Coordinate c2 = Coordinate.instance(0, 0);
		assertTrue(c1.equals(c2));
	}
	
	public void testClosestCenter(){
		Coordinate c = Coordinate.instance(10, 10);
		Set<Coordinate> closest = c.getClosest(20, 20);
		assertTrue(closest.contains(Coordinate.instance( 9, 10)));
		assertTrue(closest.contains(Coordinate.instance(11, 10)));
		assertTrue(closest.contains(Coordinate.instance(10,  9)));
		assertTrue(closest.contains(Coordinate.instance(10, 11)));		
	}
	
	public void testClosestTopCenter(){
		Coordinate c = Coordinate.instance(10, 0);
		Set<Coordinate> closest = c.getClosest(20, 20);
		assertTrue(closest.contains(Coordinate.instance( 9, 0)));		
		assertTrue(closest.contains(Coordinate.instance(11, 0)));
		assertTrue(closest.contains(Coordinate.instance(10, 1)));		
	}
	
	public void testClosestTopLeft(){
		Coordinate c = Coordinate.instance(0, 0);
		Set<Coordinate> closest = c.getClosest(20, 20);
		assertTrue(closest.contains(Coordinate.instance( 1, 0)));
		assertTrue(closest.contains(Coordinate.instance( 0, 1)));		
	}
	
	public void testClosestBottomRight(){
		Coordinate c = Coordinate.instance(19, 19);
		Set<Coordinate> closest = c.getClosest(20, 20);
		assertTrue(closest.contains(Coordinate.instance( 18, 19)));
		assertTrue(closest.contains(Coordinate.instance( 19, 18)));		
	}
	
	public void testToString(){
		Coordinate c = Coordinate.instance(12, 34);
		assertTrue(c.toString().contains("12"));
		assertTrue(c.toString().contains("34"));
	}

}
